package com.qtu.order_service.controller;

import com.qtu.entity.BmInorderlist;
import com.qtu.order_service.entity.AllOrder;
import com.qtu.order_service.entity.BmmemberOrder;
import com.qtu.order_service.service.BmInorderlistService;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Controller
@RequestMapping("api/order")
public class OrderController {
    @Autowired
    private BmInorderlistService bmInorderlistService;

    /**
     * 查询全部订单
     * @return
     */
    @RequestMapping("getAllOrder")
    @ResponseBody
    public List<AllOrder> getAllOrder(String token,Integer sellerId){
        List<AllOrder> allOrder = bmInorderlistService.getAllOrder(sellerId);
        for (AllOrder bmInorderlist : allOrder) {
            System.err.println(bmInorderlist);
        }
        return allOrder;
    }

    /**
     * 待支付订单
     * @param
     * @param
     * @return
     */
    @RequestMapping("getPayment")
    @ResponseBody
    public List<AllOrder> getPayment(String token,Integer sellerId){
        return bmInorderlistService.getPayment(sellerId);
    }


    /**
     * 待发货订单
     * @param
     * @return
     */
    @RequestMapping("getDeliverGoods")
    @ResponseBody
    public List<AllOrder> getDeliverGoods(String token,Integer sellerId){
        return bmInorderlistService.getDeliverGoods(sellerId);
    }

    /**
     * 待收货订单
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("getReceivingGoods")
    public List<AllOrder> getReceivingGoods(String token,Integer sellerId){
        return bmInorderlistService.getReceivingGoods(sellerId);
    }

    /**
     * 已完成订单
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping("getCompleted")
    public List<AllOrder> getCompleted(String token,Integer sellerId){
        return bmInorderlistService.getCompleted(sellerId);
    }

    /**
     * 订单详情
     * @param
     * @return
     */
    @RequestMapping("getDetails")
    @ResponseBody
    public List<BmmemberOrder> getDetails(String token, Integer orderId){
        try {
            List<BmmemberOrder> details = bmInorderlistService.getDetails(orderId);
            for (BmmemberOrder detail : details) {
                System.err.println(detail);
            }
            return details;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}